#-------------------------------------------------------------------------------
# create a deck of cards
# need a list a of suites
# list of all possible product values
# can use ranges in for loops [for i in range ()
# store face values in list and use for loops
#-------------------------------------------------------------------------------
import random
deck = []
suites = ("spades", "hearts", "clovers", "diamonds")
numbers = range(2, 11)
faces = ["jack", "queen","king", "ace"]
fvalues = [11, 12, 13, 14]
values = []
card1 = []
card2 =[]

def newdeck():
    deck = []


for x in numbers:
    values.append(str(x))
values.extend(faces)

for y in values:
    for z in suites:
        card = [y,z]
        deck.append(card)

def main():
    asd = True
    while asd:
        card1 = []
        card2 = []
        doit = True
        deck1 = []
        random.shuffle(deck)
        for i in range (0,26):
            h1 = random.choice(deck)
            deck1.append(h1)
            deck.remove(h1)
        deck2 = []
        for i in range (0,26):
            h2 = random.choice(deck)
            deck2.append(h2)
            deck.remove(h2)
        faces = fvalues
        while doit:
            ask = input("Press any key to continue.")#waiting for continue
            if ask == "shuffle":
                print("shuffled")
                random.shuffle(deck1)
                random.shuffle(deck2)
            card1.extend([deck1.pop(0)])#looks for the top card
            card2.extend([deck2.pop(0)])#looks for top card
            if ask == "ply1":
                print("player1")
                deck1.extend(card1)#adds both cards to deck 2
                deck1.extend(card2)
                card1 = []
                card2 = []
                print(len(deck1))
                print(len(deck2))
            elif ask == "ply2":
                print("player2")
                deck2.extend(card1)#adds both cards to deck 2
                deck2.extend(card2)
                card1 = []
                card2 = []
                print(len(deck1))
                print(len(deck2))
            else:
                print(card1)#prints out both the cards
                print(card2)
                if card1[len(card1)-1][0] > card2[len(card2)-1][0]:#if the value of the first card > 2nd
                    print("player1")
                    deck1.extend(card1)#adds both cards to deck 2
                    deck1.extend(card2)
                    card1 = []
                    card2 = []
                elif card2[len(card2)-1][0] > card1[len(card1)-1][0]:#if value of 2nd card> 1st
                    print("player2")
                    deck2.extend(card1)#adds both cards to deck 2
                    deck2.extend(card2)
                    card1 = []
                    card2 = []
                elif card1[len(card1)-1][0] == card2[len(card2)-1][0]:
                    #waitfortrue = False
                    #while waitfortrue== False:
                    #    ask = input("War! Type ''go'' to continue!")#waiting for continue
                    #    if ask == "go":
                    #        waitfortrue = True
                    if (len(deck1) < 8 or len(deck2) < 8):
                        rnumb = random.randint(1,2)
                        if rnumb == 1:
                            print("Player 1 won random toss")
                            deck1.extend(card1)#adds both cards to deck 2
                            deck1.extend(card2)
                            card1 = []
                            card2 = []
                        if rnumb == 2:
                            print("Player 1 won random toss")
                            deck2.extend(card1)#adds both cards to deck 2
                            deck2.extend(card2)
                            card1 = []
                            card2 = []
                    else:
                        print("equal")
                        fdraw1 = []
                        fdraw2 = []
                        fdraw3 = []
                        ffinal = []
                        sdraw1 = []
                        sdraw2 = []
                        sdraw3 = []
                        sfinal = []
                        fdraw1.extend([deck1.pop(1)])#drawing 3
                        fdraw2.extend([deck1.pop(2)])#drawing 3
                        fdraw3.extend([deck1.pop(3)])#drawing 3
                        ffinal.extend([deck1.pop(4)])#looks for the top card
                        sdraw1.extend([deck2.pop(1)])#drawing 3
                        sdraw2.extend([deck2.pop(2)])#drawing 3
                        sdraw3.extend([deck2.pop(3)])#drawing 3
                        sfinal.extend([deck2.pop(4)])#looks for the top card
                        print("Top 3 cards of deck 1: ", fdraw1, " ",fdraw2 , " ", fdraw3)
                        print("Top 3 cards of deck 2: ", sdraw1, " ",sdraw2 , " ", sdraw3)
                        print(sfinal)#prints out both the cards
                        print(ffinal)
                        if ffinal[len(ffinal)-1][0] > sfinal[len(sfinal)-1][0]:#if the value of the first card > 2nd
                            print("player1")
                            deck1.extend(card1)
                            deck1.extend(fdraw1)
                            deck1.extend(fdraw2)
                            deck1.extend(fdraw3)
                            deck1.extend(ffinal)
                            deck1.extend(card2)
                            deck1.extend(sdraw1)
                            deck1.extend(sdraw2)
                            deck1.extend(sdraw3)
                            deck1.extend(sfinal)
                            card1 = []
                            fdraw1 = []
                            fdraw2 = []
                            fdraw3 = []
                            ffinal = []
                            card2 = []
                            sdraw1 = []
                            sdraw2 = []
                            sdraw3 = []
                            sfinal = []
                        elif sfinal[len(sfinal)-1][0] > ffinal[len(ffinal)-1][0]:#if value of 2nd card> 1st
                            print("player2")
                            deck2.extend(card1)
                            deck2.extend(fdraw1)
                            deck2.extend(fdraw2)
                            deck2.extend(fdraw3)
                            deck2.extend(ffinal)
                            deck2.extend(card2)
                            deck2.extend(sdraw1)
                            deck2.extend(sdraw2)
                            deck2.extend(sdraw3)
                            deck2.extend(sfinal)
                            card1 = []
                            fdraw1 = []
                            fdraw2 = []
                            fdraw3 = []
                            ffinal = []
                            card2 = []
                            sdraw1 = []
                            sdraw2 = []
                            sdraw3 = []
                            sfinal = []
                        elif sfinal[len(sfinal)-1][0] == ffinal[len(ffinal)-1][0]:
                            print("NUMBERs EQUAL")
                            rnumb = random.randint(1,3)
                            if rnumb == 1:
                                print("Player 1 won random toss")
                                deck1.extend(card1)
                                deck1.extend(fdraw1)
                                deck1.extend(fdraw2)
                                deck1.extend(fdraw3)
                                deck1.extend(ffinal)
                                deck1.extend(card2)
                                deck1.extend(sdraw1)
                                deck1.extend(sdraw2)
                                deck1.extend(sdraw3)
                                deck1.extend(sfinal)
                                card1 = []
                                fdraw1 = []
                                fdraw2 = []
                                fdraw3 = []
                                ffinal = []
                                card2 = []
                                sdraw1 = []
                                sdraw2 = []
                                sdraw3 = []
                                sfinal = []
                            if rnumb == 2:
                                print("Player 2 won random toss")
                                deck2.extend(card1)
                                deck2.extend(fdraw1)
                                deck2.extend(fdraw2)
                                deck2.extend(fdraw3)
                                deck2.extend(ffinal)
                                deck2.extend(card2)
                                deck2.extend(sdraw1)
                                deck2.extend(sdraw2)
                                deck2.extend(sdraw3)
                                deck2.extend(sfinal)
                                card1 = []
                                fdraw1 = []
                                fdraw2 = []
                                fdraw3 = []
                                ffinal = []
                                card2 = []
                                sdraw1 = []
                                sdraw2 = []
                                sdraw3 = []
                                sfinal = []
                            if rnumb == 3:
                                print("Player 2 won random toss")
                                deck2.extend(card1)
                                deck2.extend(fdraw1)
                                deck2.extend(fdraw2)
                                deck2.extend(fdraw3)
                                deck2.extend(ffinal)
                                deck2.extend(card2)
                                deck2.extend(sdraw1)
                                deck2.extend(sdraw2)
                                deck2.extend(sdraw3)
                                deck2.extend(sfinal)
                                card1 = []
                                fdraw1 = []
                                fdraw2 = []
                                fdraw3 = []
                                ffinal = []
                                card2 = []
                                sdraw1 = []
                                sdraw2 = []
                                sdraw3 = []
                                sfinal = []
                print(len(deck1))
                print(len(deck2))
                if (len(deck1) == 0):
                    print("Player 2 wins!")
                    waitfortrue = False
                    while waitfortrue== False:
                        ask = input("Would you like to play again?")#waiting for continue
                        if ask == "no":
                            doit = False
                            asd = False
                            waitfortrue = True
                        elif ask == "yes":
                            newdeck()
                            print("Ending game")
                            waitfortrue = True
                            doit = False
                elif (len(deck2) == 0):
                    print("Player 1 wins!")
                    waitfortrue = False
                    while waitfortrue== False:
                        ask = input("Would you like to play again?")#waiting for continue
                        if ask == "no":
                            doit = False
                            asd = False
                            waitfortrue = True
                        elif ask == "yes":
                            newdeck()
                            print("Ending game")
                            waitfortrue = True
                            doit = False
    pass

if __name__ == '__main__':
    main()
